import CryptoJS from 'crypto-js';

// AES加密（ECB模式 + Pkcs7填充）
export const aesEncrypt = (str, key) => {
  const utf8Key = CryptoJS.enc.Utf8.parse(key);  // 密钥格式化‌:ml-citation{ref="3,5" data="citationList"}
  const encrypted = CryptoJS.AES.encrypt(str, utf8Key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return encrypted.toString();  // 返回Base64格式密文‌:ml-citation{ref="3,4" data="citationList"}
};
// AES解密
export const aesDecrypt = (ciphertext, key) => {
  const utf8Key = CryptoJS.enc.Utf8.parse(key);
  const decrypted = CryptoJS.AES.decrypt(ciphertext, utf8Key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  });
  return decrypted.toString(CryptoJS.enc.Utf8);  // 转为UTF-8明文‌:ml-citation{ref="3,6" data="citationList"}
};